function FactoryUnSelectReplace takes nothing returns nothing
	local timer t = GetExpiredTimer()
	local unit factory = LoadUnitHandle(udg_HT , GetHandleId(t) , 3)
	call IssueImmediateOrder(factory , "thunderclap")
	call PauseTimer(t)
	call FlushChildHashtable(udg_HT , GetHandleId(t))
	call DestroyTimer(t)
	//--
	set t = null
	set factory = null
endfunction

function Trig_FactoryUnSelect_Actions takes nothing returns nothing
	local timer t = null
	//--
	if HaveSavedBoolean(udg_UnitTypeDataHashTable , GetUnitTypeId(GetTriggerUnit()) , StringHash("IS_FACTORY_PAGE")) and GetOwningPlayer(GetTriggerUnit()) == GetTriggerPlayer() then
		set t = CreateTimer()
		call SaveUnitHandle(udg_HT , GetHandleId(t) , 3 , GetTriggerUnit())
		call TimerStart(t , 0.01 , false , function FactoryUnSelectReplace)
	endif
	//--
	set t = null
endfunction

//===========================================================================
function InitTrig_FactoryUnSelect takes nothing returns nothing
	set gg_trg_FactoryUnSelect = CreateTrigger()
	call TriggerRegisterPlayerForceUnitEvent(gg_trg_FactoryUnSelect , EVENT_PLAYER_UNIT_DESELECTED)
	call TriggerAddAction( gg_trg_FactoryUnSelect, function Trig_FactoryUnSelect_Actions )
endfunction